package com.fat.spzx.manager.controller;

import com.fat.spzx.manager.service.SysRoleService;
import com.fat.spzx.model.dto.system.SysRoleDto;
import com.fat.spzx.model.entity.system.SysRole;
import com.fat.spzx.model.vo.common.Result;
import com.fat.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 角色接口
 * @author : fat
 */
@Tag(name = "角色模块接口")
@RestController
@RequestMapping(value = "/admin/system/sysRole")
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;

    /**
     * 角色列表接口
     */
    @Operation(summary = "角色列表接口")
    @PostMapping("/findByPage/{current}/{limit}")
    public Result findByPage(@PathVariable("current") Integer current,
                             @PathVariable("limit") Integer limit,
                             @RequestBody SysRoleDto sysRoleDto
                             ){
        PageInfo<SysRole> pageInfo = sysRoleService.findByPage(current,limit,sysRoleDto);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    /**
     * 添加角色接口
     */
    @Operation(summary = "添加角色接口")
    @PostMapping("/addSysRole")
    public Result addSysRole(@RequestBody SysRole sysRole){
        sysRoleService.addSysRole(sysRole);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 修改角色接口
     */
    @Operation(summary = "修改角色接口")
    @PutMapping("/updateSysRole")
    public Result updateSysRole(@RequestBody SysRole sysRole){
        sysRoleService.updateSysRole(sysRole);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 删除角色接口
     */
    @Operation(summary = "删除角色接口")
    @DeleteMapping("/deleteSysRole/{id}")
    public Result deleteSysRole(@PathVariable("id") Integer id){
        sysRoleService.deleteSysRole(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }


    /**
     * 查询所有角色接口
     */
    @Operation(summary = "查询所有角色接口")
    @GetMapping(value = "/findAllRoles/{userId}")
    public Result findAllRoles(@PathVariable("userId") Long userId){
        Map<String, Object> resultMap = sysRoleService.findAllRoles(userId);
        return Result.build(resultMap,ResultCodeEnum.SUCCESS);
    }

}
